package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import com.lagou.edu.utils.ResultMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {

	@Autowired
	private ResumeService resumeService;

	@ResponseBody
	@RequestMapping("/main")
	public ModelAndView index(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("resume_list");
		return modelAndView;
	}


	@ResponseBody
	@RequestMapping("/resumeList")
	public ResultMode resumeList(){
		List<Resume> list = resumeService.selectResumeList();
		return new ResultMode(1,"查询成功", list);
	}

	@ResponseBody
	@RequestMapping("/info")
	public ResultMode info(@RequestBody Resume resume){
		Resume info = resumeService.selectResume(resume);
		return new ResultMode(1,"查询成功", info);
	}


	@ResponseBody
	@RequestMapping("/insertResume")
	public ResultMode insertResume(@RequestBody Resume resume){
		Resume info = resumeService.insertResume(resume);
		if (info == null){
			return new ResultMode(2,"操作失败");
		}
		return new ResultMode(1,"操作成功");
	}

	@ResponseBody
	@RequestMapping("/updateResume")
	public ResultMode updateResume(@RequestBody Resume resume){
		if (StringUtils.isEmpty(resume.getId())){
			return new ResultMode(2,"id不能为空");
		}
		Resume info = resumeService.updateResume(resume);
		if (info == null){
			return new ResultMode(2,"操作失败");
		}
		return new ResultMode(1,"操作成功");
	}


	@ResponseBody
	@RequestMapping("/deleteResume")
	public ResultMode deleteResume(@RequestBody Resume resume){
		resumeService.deleteResume(resume);
		return new ResultMode(1,"操作成功");
	}


}
